using System.Text.RegularExpressions;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class RegexRuleAttributeTest
    {

        private const string expectedRegEx = "aaa";


        [Test]
        public void CheckValues()
        {
            const RegexOptions regexOptions = RegexOptions.Multiline;
            var ruleAttribute = new RegexRuleAttribute(expectedRegEx);
            Assert.AreEqual(expectedRegEx, ruleAttribute.ValidationExpression);
            var propertyRule = (RegexRule)ruleAttribute.CreateRule(new MockPropertyDescriptor<string>("foo"));
            var parameterRule = (RegexRule)ruleAttribute.CreateRule(new MockParameterDescriptor<string>("foo"));

            Assert.AreEqual(expectedRegEx, propertyRule.ValidationExpression);
            Assert.AreEqual(expectedRegEx, parameterRule.ValidationExpression);

            ruleAttribute.RegexOptions = regexOptions;
            Assert.AreEqual(regexOptions, ruleAttribute.RegexOptions);

            propertyRule = (RegexRule)ruleAttribute.CreateRule(new MockPropertyDescriptor<string>("foo"));
            parameterRule = (RegexRule)ruleAttribute.CreateRule(new MockParameterDescriptor<string>("foo"));

            Assert.AreEqual(regexOptions, propertyRule.RegexOptions);
            Assert.AreEqual(regexOptions, parameterRule.RegexOptions);

        }


        [Test]
        public void CallAttributeTester()
        {
            AttributeTester.CheckDefaultValues<string>(new RegexRuleAttribute(expectedRegEx), true, true);
            AttributeTester.CheckNonDefaultValues<string>(new RegexRuleAttribute(expectedRegEx), true, true);
        }

    }
}